package com.jiuli_travel.utils;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;


@Data
public class PageQuery<T> {

    private Integer page = 1;

    private Integer size = 10;

    private String sortBy = "";

    private Boolean isAsc;


    public Page<T> toMp(OrderItem ... orderItems){
        Page<T> mp = new Page<>();
        //设置分页页码
        mp.setPages(page);
        //设置分页数据量
        mp.setSize(size);
        //设置排序字段
        if(!sortBy.isEmpty()){
          mp.addOrder(new OrderItem(sortBy, isAsc));
          return mp;
        }
        if (orderItems.length > 0){
            mp.addOrder(orderItems);
        }
        return mp;
    }

    public Page<T> defaultToMpByCreateTime(){
        return toMp(new OrderItem("create_time", false));
    }




}












